package com.itcast.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itcast.pojo.GoodInfo;
import com.itcast.pojo.Sku;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author JinX
 * @Date 1/14/2021 11:01 AM
 * @Version 1.0
 */
@Repository
public interface SkuMapper extends BaseMapper<Sku> {

    /**
     * 分页查找，一次查找固定1000条记录
     *
     * @param start
     * @param size
     * @return List<Sku>
     */
    @Select("select ts.id,\n" +
            "       ts.name,\n" +
            "       ts.price,\n" +
            "       ts.image,\n" +
            "       ts.update_time,\n" +
            "       ts.category_id,\n" +
            "       ts.category_name,\n" +
            "       ts.brand_name,\n" +
            "       ts.sale_num,\n" +
            "       ts.comment_num\n" +
            "from tb_sku ts\n" +
            "limit #{start},#{size};")
    List<Sku> findByPage(@Param("start") int start, @Param("size") int size);


    /**
     * 分页查询 记过封装为GoodInfo
     * @param start
     * @param size
     * @return
     */
    @Select("select ts.id,\n" +
            "       ts.name as title,\n" +
            "       ts.price,\n" +
            "       ts.image\n" +
            "from tb_sku ts\n" +
            "limit #{start},#{size};")
    List<GoodInfo> search(@Param("start") int start, @Param("size") int size);


}
